package com.ht.file.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.ht.file.entity.AdenexaModel;
import com.ht.file.service.AdenexaService;
import com.ht.right.util.CommonUtil;
import com.ht.right.util.FileCommonUtil;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class AdenexaAction extends ActionSupport implements ModelDriven<AdenexaModel>{
	private static final long serialVersionUID = 8023822012891157011L;
	private AdenexaService adenexaService;
	private AdenexaModel adenexaModel;
	
	
	public String findAllAdenexaJson(){
		String uuid = ServletActionContext.getRequest().getParameter("uuid");
		List<AdenexaModel> list = adenexaService.findAllAdenexaListJson(uuid);
		CommonUtil.toJsonStr(ServletActionContext.getResponse(), list);
		return null;
	}
	
	public String findViewAdenexaById(){
		return null;
	}
	
	public String findDowloadAdenexaById(){
		String uuid = ServletActionContext.getRequest().getParameter("uuid");
		adenexaModel = adenexaService.findViewAdenexaById(uuid);
		FileCommonUtil.dowloadFile(adenexaModel.getFilename(), adenexaModel.getFilepath(), ServletActionContext.getResponse());
		
		return null;
	}
	
	public AdenexaModel getAdenexaModel() {
		return adenexaModel;
	}

	public void setAdenexaModel(AdenexaModel adenexaModel) {
		this.adenexaModel = adenexaModel;
	}

	public AdenexaService getAdenexaService() {
		return adenexaService;
	}

	public void setAdenexaService(AdenexaService adenexaService) {
		this.adenexaService = adenexaService;
	}

	@Override
	public AdenexaModel getModel() {
		if(CommonUtil.isNullOrEmpty(adenexaModel)){
			adenexaModel = new AdenexaModel();
		}
		return adenexaModel;
	}


}
